package com.msh.bird;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * Date：2021年09月
 * Author：程Sir
 * Content: 柱体信息类
 */
public class Column extends Global {
    /**
     * 柱子中间的缝隙
     */
    public int gap;
    /**
     * 两个柱子间的距离
     */
    public int distance;

    // 对实例变量进行初始化
    public Column(int n) throws Exception {
        Random random = new Random();
        this.image = ImageIO.read(getClass().getResource("img/column.png"));
        width = image.getWidth();
        height = image.getHeight();
        gap = 144;
        distance = 245;
        x = 750 + (n - 1) * distance;
        y = random.nextInt(218) + 132;
    }

    /**
     * 柱子移动的方法
     */
    public void step() {
        Random random = new Random();
        // 移动必须是针对坐标进行操作
        x--;
        if (x == -width / 3) {
            x = distance * 3 - width / 2;
            y = random.nextInt(218) + 132;
        }
    }
}
